package day17_Inet.demo06_TCP;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

//TCP服务器端接收数据
/*
1.创建客户端的Socket对象(ServerSocket)
new ServerSocket(int port);
2.调用Serve
3.创建输入rSocket监听端口号,接收数据
accept();
getInputStream();输入流读数据
read();
4.解析数据,并在控制台显示
new String(byte[] byte, int off,int length)
5.关释放资源
close()

 */
public class Server_TCP {
    public static void main(String[] args) throws Exception{
        ServerSocket ss = new ServerSocket(8888);//创建客户端的Socket对象(ServerSocket)
        Socket accept = ss.accept();//调用ServerSocket监听端口号,接收数据
        InputStream is = accept.getInputStream();
        byte[] bytes = new byte[1024];
        int read = is.read(bytes);
        String s = new String(bytes, 0,read);
        System.out.println(s);
        int read1 = is.read(bytes);
        String s1 = new String(bytes, 0,read1);
        System.out.println(s1);
        ss.close();
    }
}
